package cn.lili.controller.order;

import cn.lili.common.aop.annotation.PreventDuplicateSubmissions;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.order.entity.dos.PrizeGoods;
import cn.lili.modules.order.order.entity.dos.PrizeOrder;
import cn.lili.modules.order.order.entity.dto.PrizeGoodsDTO;
import cn.lili.modules.order.order.entity.dto.PrizeOrderDTO;
import cn.lili.modules.order.order.entity.vo.PrizeOrderStatisticsVO;
import cn.lili.modules.order.order.service.OrderStatisticsService;
import cn.lili.modules.order.order.service.PrizeGoodsService;
import cn.lili.modules.order.order.service.PrizeOrderService;
import cn.lili.modules.promotion.entity.vos.BoxMhgoodsVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "抽奖配置")
@RequestMapping("/order/prize")
@RequiredArgsConstructor
@CrossOrigin
public class PrizeLotteryController {

    private final PrizeGoodsService prizeGoodsService;
    private final PrizeOrderService prizeOrderService;

    @GetMapping("/prizeGoodsList")
    @ApiOperation("奖品列表")
    public ResultMessage<Page<PrizeGoods>> lotteryGoodsList(PrizeGoodsDTO dto) {
        return ResultUtil.data(prizeGoodsService.lotteryGoodsList(dto));
    }

    @PostMapping("/createPrizeGoods")
    @ApiOperation("创建抽奖配置")
    @PreventDuplicateSubmissions
    public ResultMessage<Object> createPrizeGoods(@RequestBody @Validated PrizeGoods prize) {
        return prizeGoodsService.createPrizeGoods(prize);
    }

    @PostMapping("/publishPrizeGoods")
    @ApiOperation("发布奖品")
    @PreventDuplicateSubmissions
    public ResultMessage<Object> publishPrizeGoods(@RequestBody @Validated PrizeGoodsDTO dto) {
        return prizeGoodsService.publishPrizeGoods(dto);
    }

    @PostMapping("/updatePrizeConfig")
    @ApiOperation("修改奖品配置")
    @PreventDuplicateSubmissions
    public ResultMessage<Object> updatePrizeConfig(@RequestBody PrizeGoods prize) {
        return prizeGoodsService.updatePrizeConfig(prize);
    }

    @PostMapping("/deletePrizeConfig/{id}")
    @ApiOperation("删除奖品配置")
    @PreventDuplicateSubmissions
    public ResultMessage<Object> deletePrizeConfig(@PathVariable("id") String id) {
        return prizeGoodsService.deletePrizeConfig(id);
    }

    @GetMapping("/getPrizeOrderList")
    @ApiOperation("获取抽奖记录")
    public ResultMessage<Page<PrizeOrder>> getPrizeOrderList(PrizeOrderDTO dto) {
        return ResultUtil.data(prizeOrderService.getPrizeOrderList(dto));
    }

    @GetMapping("/export")
    @ApiOperation("导出抽奖记录")
    public ResultMessage<Object> export(PrizeOrderDTO dto) {
        return ResultUtil.data(prizeOrderService.export(dto));
    }


    @PostMapping("/inputExpressInfo")
    @ApiOperation("填写运单号")
    @PreventDuplicateSubmissions
    public ResultMessage<Object> inputExpressInfo(@RequestBody PrizeOrder order) {
        return prizeOrderService.inputExpressInfo(order);
    }

    @GetMapping("/prizePriceStatistics")
    @ApiOperation("抽奖金额/人数统计")
    public ResultMessage<PrizeOrderStatisticsVO> prizePriceStatistics(PrizeOrderDTO dto) {
        return ResultUtil.data(prizeOrderService.prizePriceStatistics(dto));
    }

    @GetMapping("/prizeUserCountStatistics")
    @ApiOperation("抽奖用户数量统计-弃用")
    public ResultMessage<PrizeOrderStatisticsVO> prizeUserCountStatistics(PrizeOrderDTO dto) {
        return ResultUtil.data(prizeOrderService.prizeUserCountStatistics(dto));
    }

}
